/**********************************************************************
 * SailmiPIM - modular cross-platform feature Personal Information Manager Tools.
 * Copyright(C) 2006-2014  Georg Rudoy
 *
 * Distributed under the Boost Software License, Version 1.0.
 *(See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
 **********************************************************************/

#include "infoproxy.h"
#include <QDBusInterface>
#include <QDBusReply>
#include <QIcon>
#include <sailmipim/core/icoreproxy.h>

namespace SailmiPIM
{
    namespace Loaders
    {
        InfoProxy::InfoProxy(const QString& service)
        : Service_ { service }
        , IFace_ { new QDBusInterface { service, "/com/sailmi/pim/Plugin" } }
        , Info_ { new QDBusInterface { service, "/com/sailmi/pim/Info" } }
        {
        }

        void InfoProxy::SetProxy(ICoreProxy_ptr proxy)
        {
            Info_->call("SetProxy", QVariant::fromValue(proxy));
        }

        void InfoProxy::SetPluginInstance(QObject *obj)
        {
            Info_->call("SetPluginInstance", QVariant::fromValue(obj));
        }

        void InfoProxy::Init(ICoreProxy_ptr proxy)
        {
            qDebug() << Q_FUNC_INFO;
            Info_->call("Init", QVariant::fromValue(proxy));
            qDebug() << "done";
        }

        void InfoProxy::SecondInit()
        {
            Info_->call("SecondInit");
        }

        void InfoProxy::Release()
        {
            Info_->call("Release");
        }

        QByteArray InfoProxy::GetUniqueID() const
        {
            return QDBusReply<QByteArray>(Info_->call("GetUniqueID")).value();
        }

        QString InfoProxy::GetName() const
        {
            return QDBusReply<QString>(Info_->call("GetName")).value();
        }

        QString InfoProxy::GetInfo() const
        {
            return QDBusReply<QString>(Info_->call("GetInfo")).value();
        }

        QIcon InfoProxy::GetIcon() const
        {
            return QDBusReply<QIcon>(Info_->call("GetIcon")).value();
        }

        bool InfoProxy::IsCore() const{
            return true;
        }

        const ICoreProxy_ptr& InfoProxy::GetProxy(){
            //return QDBusReply<ICoreProxy_ptr&>(Info_->call("GetProxy")).value();
            return nullptr;
        }
    }
}
